<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>就诊信息</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../css/adminmenu.css"/>
    <script type="text/javascript" src="../js/axios.js"></script>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/message.js"></script>
    <script type="text/javascript" src="../js/sort.js"></script>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body style="background-color: #ffaa7f;">
<div id="visit">
    <div class="menu">
        <div>
            <div class="title" onclick="show(this)">
                <button style="width: 200px;font-size: 20px;" onclick="location.replace('adminMenu.html');">药品信息
                </button>
            </div>
        </div>
        <hr style="border: none;">
        <div>
            <div class="title" onclick="show(this)">
                <button style="width: 200px;font-size: 20px;" onclick="location.replace('visitInformation.html');">
                    就诊信息
                </button>
            </div>
            <div class="title" onclick="show(this)">
                <button style="width: 200px;font-size: 20px;" onclick="location.replace('expenseInformation.html');">
                    报销信息
                </button>
            </div>
            <div class="con hide">
            </div>
        </div>

    </div>
    <div>
			<span style="padding: 0 0 520px 580px;">
			<button style="font-size: 20px;" onclick="location.replace('visitInformationInput.html')">就诊基本信息录入</button>
			</span>
        <table>
            <thead>
            <tr>
                <th>医保卡号</th>
                <th>编号</th>
                <th>患者名</th>
                <th>医保类别</th>
                <th>就诊时间</th>
                <th>详细信息查看</th>
                <th>执行操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(item) in result.list">
                <td>{{item.insurance_code}}</td>
                <td>{{item.healing_code}}</td>
                <td>{{item.insurance_name}}</td>
                <td>{{getRoleName(item.insurance_role)}}</td>
                <td>{{item.healing_date}}</td>
                <td>
                    <button @click="turnToDetail(item.insurance_id,item.healing_id)">查看</button>
                </td>
                <td>
                    <button @click="deleteHealing(item.healing_id)">删除</button>
                </td>
            </tr>
            </tbody>

        </table>
        <div style="text-align:  center">
            <ul class="pagination" style="margin: auto;">
                <li v-for="n in result.pages">
                    <a href="javascript:void(0);" @click="search(n)" :class="{'active' : n==result.pageNum}">{{n}}</a>
                </li>
                <li>
                    <select @change="search(1)" v-model="searchParam.onePageCount">
                        <option v-for="item in pagecountlist" :value="item">{{item}}</option>
                    </select>
                </li>
            </ul>
        </div>
    </div>

</div>
<script>
    var vue = new Vue({
        el: "#visit",
        data: {
            "result": {
                "list": {}
            },
            "searchParam": {
                "currentpage": 1,
                "onePageCount": 5
            },
            "pagecountlist": [5, 10, 20, 30, 50],
            showmsg: {
                msginfo: "",
                classobject: {
                    msg: false,
                    success: false
                }
            },
            sortMap: []
        },
        methods: {
            search: function (currentpage) {
                this.showmsg.msginfo = "";
                this.searchParam.currentpage = currentpage;

                console.log(sessionStorage.getItem("authtoken"));
                axios.post("http://localhost:8000/bracelet/release/api/gethealinglist",
                    {
                        "token": sessionStorage.getItem("authtoken"),
                        "pageNum": this.searchParam.currentpage,
                        "pageSize": this.searchParam.onePageCount
                    })
                    .then(res => {
                        this.result = res.data.result;

                    })
                    .catch(error => {
                        alert(error.errorMsg);
                    });
            },
            getRoleName: function (role) {
                return this.sortMap[role].name;
            },
            turnToDetail: function (insuranceId, healingId) {
                window.open("visitDetails.html?insuranceId=" + insuranceId + "&healingId=" + healingId);
            },
            deleteHealing: function (healingId) {
                console.log(healingId);
                axios.post("http://localhost:8000/bracelet/release/api/deletehealing",
                    {
                        "token": sessionStorage.getItem("authtoken"),
                        "healingId": healingId
                    })
                    .then(res => {
                        alert("删除成功");
                    })
                    .catch(error => {
                        alert(error.errorMsg);
                    });
                location.reload();
            }
        },
        mounted: function () {
            axios.post("http://localhost:8000/bracelet/release/api/getsort",
                {
                    "sortType": SORT.医保
                })
                .then(res => {
                    this.sortMap = res.data.result;
                })
                .catch(error => {
                    location.href = "../500.html";
                });
        },
        created: function () {
            // 数据初始化完成
            this.search(1);
        }
    })
</script>
</body>
</html>